package com.yupi.example.consumer;

import com.yupi.example.common.model.User;
import com.yupi.example.common.service.UserService;
import com.yupi.yurpc.bootstrap.ConsumerBootstrap;
import com.yupi.yurpc.proxy.ServiceProxyFactory;

/**
 * 简易服务消费者示例
 *
 * @author spring
 */
public class ConsumerExample {

    public static void main(String[] args) {
        // 服务提供者初始化
        ConsumerBootstrap.init();

        // 获取代理
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("yupi");
        // 调用
        User newUser = userService.getUser(user);
        if (newUser != null) {
            System.out.println(newUser.getName());
        } else {
            System.out.println("user == null");
        }
    }
}

/*
应该能看到输出的结果值为 0，而不是 1，
说明调用了 MockServiceProxy 模拟服务代理。
当然也可以通过 Debug 的方式进行验证。
Connected to the target VM, address: '127.0.0.1:64381', transport: 'socket'
yupi  1
Disconnected from the target VM, address: '127.0.0.1:64381', transport: 'socket'
 */